#include "input.h"
#include <windows.h>
#include <iostream>

// 按键按下事件回调函数
void onKeyDown(const InputEvent& event) {
    std::cout << "Key Down: " << event.keyCode << std::endl;
}

// 鼠标左键按下事件回调函数
void onMouseLeftDown(const InputEvent& event) {
    std::cout << "Mouse Left Down: (" << event.mouse.x << ", " << event.mouse.y << ")" << std::endl;
}

int main() {
    // 创建 InputHandler 对象
    InputHandler inputHandler;

    // 注册按键按下事件回调
    inputHandler.registerCallback(InputEventType::KeyDown, onKeyDown);
    // 注册鼠标左键按下事件回调
    inputHandler.registerCallback(InputEventType::MouseDown, onMouseLeftDown);

    // 模拟按键按下事件
    keybd_event(VK_SPACE, 0, 0, 0);

    // 模拟鼠标左键按下事件
    SetCursorPos(100, 100);
    mouse_event(MOUSEEVENTF_LEFTDOWN, 100, 100, 0, 0);

    // 更新 InputHandler 以处理输入事件
    inputHandler.update();

    // 检查按键状态
    if (inputHandler.isKeyDown(VK_SPACE)) {
        std::cout << "Space key is down." << std::endl;
    }

    // 检查鼠标左键状态
    if (inputHandler.isMouseButtonDown(MouseButton::Left)) {
        std::cout << "Mouse left button is down." << std::endl;
    }

    // 模拟按键释放事件
    keybd_event(VK_SPACE, 0, KEYEVENTF_KEYUP, 0);
    // 模拟鼠标左键释放事件
    mouse_event(MOUSEEVENTF_LEFTUP, 100, 100, 0, 0);

    // 再次更新 InputHandler 以处理输入事件
    inputHandler.update();

    // 检查按键状态
    if (inputHandler.isKeyUp(VK_SPACE)) {
        std::cout << "Space key is up." << std::endl;
    }

    // 检查鼠标左键状态
    if (inputHandler.isMouseButtonUp(MouseButton::Left)) {
        std::cout << "Mouse left button is up." << std::endl;
    }

    return 0;
}